import 'package:flutter/material.dart';
import 'package:xws/helpers/as_t.dart';
import 'package:xws/utils/theme_util.dart';

String _getContent(String type) {
  switch (type) {
    case 'UPLOAD_GOODS':
      return '上传物品';
    case 'SEND_GOODS':
      return '送出物品';
    case 'GET_GOODS':
      return '获赠物品';
    case 'SHARE_GOODS':
      return '分享物品';
    default:
      return '其他操作';
  }
}

class PointChangedObj {
  PointChangedObj.fromJson(Map<String, dynamic> d) {
    oldLevel = asT<int>(d['oldLevel']);
    newLevel = asT<int>(d['newLevel']);
    oldIntegral = asT<int>(d['oldIntegral']);
    newIntegral = asT<int>(d['newIntegral']);
    changeContent = _getContent(asT<String>(d['changeType'])) + ' , 获得 ';
  }

  late int oldLevel;
  late int newLevel;
  late int oldIntegral;
  late int newIntegral;
  late String changeContent;

  String get changeCount => (newIntegral - oldIntegral).toString();
}

/// 积分变动信息
class PointChanged extends StatelessWidget {
  const PointChanged({Key? key, required this.obj}) : super(key: key);

  final PointChangedObj obj;

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(20.0),
      child: RichText(
        text: TextSpan(
          style: TextStyle(fontSize: 14, color: black(context)),
          text: obj.changeContent,
          children: <TextSpan>[
            TextSpan(
              style: TextStyle(color: theme(context), fontWeight: FontWeight.bold),
              text: obj.changeCount,
            ),
            const TextSpan(text: ' 积分'),
          ],
        ),
      ),
    );
  }
}
